package com.and.rsspect;

import java.io.Serializable;
import java.util.List;

public class AndroidRSSDoc  implements Serializable {

	private static final long serialVersionUID = 649162683570000798L;

	/**
	 * the default document encoding of "UTF-8"
	 */
	private String encoding = System.getProperty("file.encoding");

	/**
	 * the default XML version of "1.0"
	 */
	private String xmlVersion = "1.0";

	private Generator libVersion;

	public AndroidRSSDoc() throws Exception {
		
	}

	/**
	 * @return the RSSpect library version in the form of a generator element.
	 *         This element is output for all feeds that are generated by
	 *         RSSpect.
	 */
	public Generator getLibVersion() {
		return new Generator(libVersion);
	}

	/**
	 * 
	 * @param channel
	 *            the unique channel element (required)
	 * @param attributes
	 *            additional attributes (optional)
	 * @param extensions
	 *            additional extensions (optional)
	 * @return an immutable RSS object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static RSS buildRSS(Channel channel, List<Attribute> attributes,
			List<Extension> extensions) throws RSSpectException {
		return new RSS(channel, attributes, extensions);
	}

	/**
	 * 
	 * @param name
	 *            the attribute name.
	 * @param value
	 *            the attribute value.
	 * @return an immutable Attribute object.
	 * @throws RSSpectException
	 *             if the data is not valid.
	 */
	public static Attribute buildAttribute(String name, String value)
			throws RSSpectException {
		return new Attribute(name, value);
	}

	/**
	 * 
	 * @param author
	 *            the author element. (required)
	 * @return an immutable Author object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Author buildAuthor(String author) throws RSSpectException {
		return new Author(author);
	}

	/**
	 * @param domain
	 *            the domain attribute
	 * @param category
	 *            the category text
	 * @return an immutable Category object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Category buildCategory(Attribute domain, String category)
			throws RSSpectException {
		return new Category(domain, category);
	}

	/**
	 * 
	 * @param title
	 *            the title element.
	 * @param link
	 *            the link element.
	 * @param description
	 *            the description element.
	 * @param language
	 *            the language element.
	 * @param copyright
	 *            the copyright element.
	 * @param managingEditor
	 *            the managingEditor element.
	 * @param webMaster
	 *            the webMaster element.
	 * @param pubDate
	 *            the pubDate element.
	 * @param lastBuildDate
	 *            the lastBuildDate element.
	 * @param categories
	 *            the list of categories
	 * @param generator
	 *            the generator element.
	 * @param docs
	 *            the docs element.
	 * @param cloud
	 *            the cloud element.
	 * @param ttl
	 *            the ttl element.
	 * @param image
	 *            the image element.
	 * @param rating
	 *            the rating element.
	 * @param textInput
	 *            the textInput element.
	 * @param skipHours
	 *            the skipHours element.
	 * @param skipDays
	 *            the skipDays element.
	 * @param items
	 *            the list of items.
	 * @param extensions
	 *            the list of extensions.
	 * @return an immutable Channel object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Channel buildChannel(Title title, Link link,
			Description description, Language language, Copyright copyright,
			ManagingEditor managingEditor, WebMaster webMaster,
			PubDate pubDate, LastBuildDate lastBuildDate,
			List<Category> categories, Generator generator, Docs docs,
			Cloud cloud, TTL ttl, Image image, Rating rating,
			TextInput textInput, SkipHours skipHours, SkipDays skipDays,
			List<Extension> extensions, List<Item> items)
			throws RSSpectException {
		return new Channel(title, link, description, language, copyright,
				managingEditor, webMaster, pubDate, lastBuildDate, categories,
				generator, docs, cloud, ttl, image, rating, textInput,
				skipHours, skipDays, extensions, items);
	}

	public static Channel buildChannel(String title, String link, String description,
			String language, String copyright, String generator, Image image,List<Item> items) throws RSSpectException {
		return new Channel(new Title(title), new Link(link), new Description(
				description), new Language(language), new Copyright(copyright),
				null, null, null, null, null, new Generator(generator), null,
				null, null, image, null, null, null, null, null, items);
	}

	/**
	 * 
	 * @param attributes
	 *            the list of attributes.
	 * @return an immutable Cloud object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Cloud buildCloud(List<Attribute> attributes) throws RSSpectException {
		return new Cloud(attributes);
	}

	/**
	 * 
	 * @param comments
	 *            the comments.
	 * @return an immutable Comments object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Comments buildComments(String comments) throws RSSpectException {
		return new Comments(comments);
	}

	/**
	 * 
	 * @param copyright
	 *            the copyright.
	 * @return an immutable Copyright object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Copyright buildCopyright(String copyright) throws RSSpectException {
		return new Copyright(copyright);
	}

	/**
	 * 
	 * @param description
	 *            the description.
	 * @return an immutable Description object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Description buildDescription(String description)
			throws RSSpectException {
		return new Description(description);
	}

	/**
	 * 
	 * @param docs
	 *            the documentation information.
	 * @return an immutable Docs object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Docs buildDocs(String docs) throws RSSpectException {
		return new Docs(docs);
	}

	/**
	 * 
	 * @param attributes
	 *            should contain url, length and type
	 * @return an immutable Enclosure object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Enclosure buildEnclosure(List<Attribute> attributes)
			throws RSSpectException {
		return new Enclosure(attributes);
	}

	/**
	 * 
	 * @param elementName
	 *            the name of the extension element.
	 * @param attributes
	 *            additional attributes.
	 * @param content
	 *            the content of the extension element.
	 * @return an immutable Extension object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Extension buildExtension(String elementName,
			List<Attribute> attributes, String content) throws RSSpectException {
		return new Extension(elementName, attributes, content);
	}

	/**
	 * @param text
	 *            the text content.
	 * @return an immutable Generator object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Generator buildGenerator(String text) throws RSSpectException {
		return new Generator(text);
	}

	/**
	 * 
	 * @param isPermaLink
	 *            the isPermaLink attributes.
	 * @param guid
	 *            the guid data.
	 * @return an immutable GUID object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static GUID buildGUID(Attribute isPermaLink, String guid)
			throws RSSpectException {
		return new GUID(isPermaLink, guid);
	}

	/**
	 * 
	 * @param height
	 *            should be a number 400 or less
	 * @return an immutable Height object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Height buildHeight(String height) throws RSSpectException {
		return new Height(height);
	}

	/**
	 * 
	 * @param url
	 *            the url element.
	 * @param title
	 *            the title element.
	 * @param link
	 *            the link element.
	 * @param width
	 *            the width element.
	 * @param height
	 *            the height element.
	 * @param description
	 *            the description element.
	 * @return an immutable Image object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Image buildImage(URL url, Title title, Link link, Width width,
			Height height, Description description) throws RSSpectException {
		return new Image(url, title, link, width, height, description);
	}
	
	public static Image buildImage(String url,String title,String link) throws RSSpectException{
		return new Image(new URL(url),new Title(title),new Link(link),null,null,null);
	}

	/**
	 * 
	 * @param title
	 *            the title element.
	 * @param link
	 *            the link element.
	 * @param description
	 *            the description element.
	 * @param author
	 *            the author element.
	 * @param categories
	 *            the list of categories.
	 * @param comments
	 *            the comments element.
	 * @param enclosure
	 *            the enclosure element.
	 * @param guid
	 *            the guid element.
	 * @param pubDate
	 *            the published date element.
	 * @param source
	 *            the source element.
	 * @param extensions
	 *            the list of extensions.
	 * @return an immutable Item object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Item buildItem(Title title, Link link, Description description,
			Author author, List<Category> categories, Comments comments,
			Enclosure enclosure, GUID guid, PubDate pubDate, Source source,
			List<Extension> extensions) throws RSSpectException {
		return new Item(title, link, description, author, categories, comments,
				enclosure, guid, pubDate, source, extensions);
	}

	/**
	 * 
	 * @param language
	 *            the language.
	 * @return an immutable Language object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Language buildLanguage(String language) throws RSSpectException {
		return new Language(language);
	}

	/**
	 * 
	 * @param lastBuildDate
	 *            the last build date.
	 * @return an immutable LastBuildDate object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static LastBuildDate buildLastBuildDate(String lastBuildDate)
			throws RSSpectException {
		return new LastBuildDate(lastBuildDate);
	}

	/**
	 * 
	 * @param link
	 *            the link information.
	 * @return an immutable Link object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Link buildLink(String link) throws RSSpectException {
		return new Link(link);
	}

	/**
	 * 
	 * @param managingEditor
	 *            the managing editor.
	 * @return an immutable ManagingEditor object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static ManagingEditor buildManagingEditor(String managingEditor)
			throws RSSpectException {
		return new ManagingEditor(managingEditor);
	}

	/**
	 * 
	 * @param name
	 *            the name.
	 * @return an immutable Name object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Name buildName(String name) throws RSSpectException {
		return new Name(name);
	}

	/**
	 * 
	 * @param pubDate
	 *            the published date.
	 * @return an immutable PubDate object.
	 * @throws RSSpectException
	 *             If the dateTime format is invalid.
	 */
	public static PubDate buildPubDate(String pubDate) throws RSSpectException {
		return new PubDate(pubDate);
	}

	/**
	 * 
	 * @param rating
	 *            the rating information.
	 * @return an immutable Rating object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Rating buildRating(String rating) throws RSSpectException {
		return new Rating(rating);
	}

	/**
	 * 
	 * @param skipDays
	 *            the days to skip.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 * @return an immutable SkipDays object.
	 */
	public static SkipDays buildSkipDays(List<Day> skipDays) throws RSSpectException {
		return new SkipDays(skipDays);
	}

	/**
	 * 
	 * @param skipHours
	 *            the hours to skip.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 * @return an immutable SkipHours object.
	 */
	public static SkipHours buildSkipHours(List<Hour> skipHours)
			throws RSSpectException {
		return new SkipHours(skipHours);
	}

	/**
	 * @param day
	 *            the day of the week.
	 * @return a Day object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Day buildDay(String day) throws RSSpectException {
		return new Day(day);
	}

	/**
	 * @param hour
	 *            the hour of the day.
	 * @return an Hour object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Hour buildHour(String hour) throws RSSpectException {
		return new Hour(hour);
	}

	/**
	 * 
	 * @param url
	 *            the url attribute.
	 * @param source
	 *            the source information.
	 * @return an immutable Source object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Source buildSource(Attribute url, String source)
			throws RSSpectException {
		return new Source(url, source);
	}

	/**
	 * 
	 * @param title
	 *            the title element.
	 * @param description
	 *            the description element.
	 * @param name
	 *            the name element.
	 * @param link
	 *            the link element.
	 * @return an immutable TextInput object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static TextInput buildTextInput(Title title, Description description,
			Name name, Link link) throws RSSpectException {
		return new TextInput(title, description, name, link);
	}

	/**
	 * 
	 * @param title
	 *            the title.
	 * @return an immutable Title object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Title buildTitle(String title) throws RSSpectException {
		return new Title(title);
	}

	/**
	 * 
	 * @param ttl
	 *            the time to live.
	 * @return an immutable TTL object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static TTL buildTTL(String ttl) throws RSSpectException {
		return new TTL(ttl);
	}

	/**
	 * 
	 * @param url
	 *            the url.
	 * @return an immutable URL object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static URL buildURL(String url) throws RSSpectException {
		return new URL(url);
	}

	/**
	 * 
	 * @param webMaster
	 *            the web master.
	 * @return an immutable WebMaster object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static WebMaster buildWebMaster(String webMaster) throws RSSpectException {
		return new WebMaster(webMaster);
	}

	/**
	 * 
	 * @param width
	 *            the width.
	 * @return an immutable Width object.
	 * @throws RSSpectException
	 *             if the format of the data is not valid.
	 */
	public static Width buildWidth(String width) throws RSSpectException {
		return new Width(width);
	}

	

	/**
	 * @return the xml encoding of the document eg. UTF-8
	 */
	public String getEncoding() {
		return encoding;
	}

	/**
	 * @return the xml document version of the document eg. 1.0
	 */
	public String getXmlVersion() {
		return xmlVersion;
	}

	void setEncoding(String encoding) {
		this.encoding = encoding;
	}

	void setXmlVersion(String xmlVersion) {
		this.xmlVersion = xmlVersion;
	}

}